<?php

namespace App\Http\Controllers\Admin;

use App\Admin\Member;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
use Input;

class MemberController extends Controller
{
    public function index()
    {
        $data = Member::get();
        return view('admin.member.index',compact('data'));
    }

    public function add()
    {
        if(Input::method() == 'POST'){
            $result = Member::insert([
                'username' => Input::get('username'),
                'password' => bcrypt('password'),
                'gender'   => Input::get('gender'),
                'mobile'   => Input::get('mobile'),
                'email'    => Input::get('email'),
                'avatar'   => Input::get('avatar'),
                'country_id'  =>  Input::get('country_id'),
                'province_id'  =>  Input::get('province_id'),
                'city_id'  =>  Input::get('city_id'),
                'county_id'  =>  Input::get('county_id'),
                'type'       =>  Input::get('type'),
                'status'     =>  Input::get('status'),
                'created_at'  =>  date('Y-m-d H:i:s')
            ]);
            return $result ? 1: 0;
        }else {
            $country = DB::table('area')->where('pid','0')->get();
            return view('admin.member.add',compact('country'));
        }
    }
    //ajax四级联动获取下级地区
    public function getAreaById()
    {
        $id = Input::get();
        $data = DB::table('area')->where('pid',$id)->get();
        return response()->json($data);
    }
}
